<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>get&&post</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
    $(function () {
      $('#btn1').click(() => {
        $.ajax({
          url: '/reg',
          data: {
            userName: $('#user').val(),
            passWord: $('#pass').val(),
          },
          dataType: 'json'
        }).then(data => {
          console.log('成功了', data);
          if (data.error == 0) {
            alert('成功了')

          } else {
            alert(data.msg)
          }

        }, err => {
          console.log('失败了', err);
        })

      });
      //登陆
      $('#btn2').click(() => {
        $.ajax({
          url: '/login',
          method: 'post',
          data: {
            userName: $('#user').val(),
            passWord: $('#pass').val(),
          },
          dataType: 'json'
        }).then(data => {
          console.log('成功了', data);
          if (data.error == 0) {
            alert('成功了')

          } else {
            alert(data.msg)
          }

        }, err => {
          console.log('失败了', err);
        })

      });


    })
  </script>
</head>

<body>
  <div>
    用户名：<input type="text" id="user"><br>
    密码：<input type="password" id="pass"><br>
    <button id="btn1">注册</button><button id="btn2">登陆</button>
  </div>

</body>

</html>